package com.yuan.zs.ui.account;

import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;

import com.yuan.base.framework.BaseFrameworkActivity;
import com.yuan.base.framework.bean.TipResult;
import com.yuan.base.framework.http.BaseHttpCallBack;
import com.yuan.base.framework.http.BaseHttpRequest;
import com.yuan.base.utils.DialogUtil;
import com.yuan.zs.R;
import com.yuan.zs.Urls;

import java.util.HashMap;

/**
 * 账号管理
 */
public class AccountManageActivity extends BaseFrameworkActivity {

	private LinearLayout ll_bind_main_account;

	@Override
	protected int getLayoutId() {
		return R.layout.activity_account_manage;
	}

	@Override
	protected void bindViews() {
		ll_bind_main_account = findViewById(R.id.ll_bind_main_account);
		ll_bind_main_account.setOnClickListener(v -> {
			DialogUtil.input(this, "绑定主账号", "", "确认", (dialog, content, userName) -> {
				bindAccount(content);
			}, "取消", null);
		});
		setOnClickListener(R.id.ll_search_account, v -> startActivity(new Intent(this, AccountManageSearchActivity.class)));
		setOnClickListener(R.id.ll_sh_account, v -> startActivity(new Intent(this, AccountManageSHActivity.class)));
	}


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	private void bindAccount(String phone) {
		String url = Urls.getUrl(Urls.applyBindAccount);
		HashMap<String, Object> params = new HashMap<>();
		params.put("target", phone);
		BaseHttpRequest.post(url, params, new BaseHttpCallBack<TipResult>() {

			@Override
			public void onSuccess(TipResult result) {
				if (result.isSuccess()) {
					showToast("提交成功,请等待主账号审核");
				} else {
					showToast(result.getMessage());
				}
			}
		});
	}
}
